class SegmentUtils{
    SegmentUtils(){
        this.segmentName = Array(AR_STR, "segmentName");
        this.startAddr = Array(AR_LONG, "startAddr");
        this.endAddr = Array(AR_LONG, "endAddr");
        Message("段地址初始化开始～\n");
        this.initSegment();
        Message("段地址初始化完成\n");
    }

    ~SegmentUtils(){}

    initSegment(){
        auto x, name;
        for (x = GetFirstModule(); x != BADADDR; x = GetNextModule(x)){
            name = GetModuleName(x); 
            this.segmentName.add(name);
            this.startAddr.add(x);
            this.endAddr.add(x + GetModuleSize(x));
        }
    }

    forEcho(){
        auto i;
        Message("len: %d\n", this.segmentName.len);
        for(i = 0; i < this.segmentName.len; i = i + 1){
            Message("segmentName: %s, startAddr: 0x%x, endAddr: 0x%x \n", this.segmentName.get(i), this.startAddr.get(i), this.endAddr.get(i));
        }
        Message("\n");
    }

    getStartAddrBySegmentName(segmentNameParam){
        auto index;
        index = this.segmentName.includedContain(segmentNameParam);
        if(index == -1){
            return -1;
        }

        return this.startAddr.get(index);
    }

    getEndAddrBySegmentName(segmentNameParam){
        auto index;
        index = this.segmentName.includedContain(segmentNameParam);
        if(index == -1){
            return -1;
        }

        return this.endAddr.get(index);
    }
}